<template>
  <el-dialog title="分配角色" :visible="isShowDialog" @close="btnCancel">
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">
        {{ role.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <el-button size="small" type="primary" @click="btnOK">确定</el-button>
      <el-button size="small" @click="btnCancel">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/settings'
import { getUserDetailById } from '@/api/user'
import { assignRole } from '@/api/employee'
export default {
  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleList: [],
      roleIds: [],
      employeeId: ''
    }
  },
  async created() {
    const { rows } = await getRoleList({
      page: 1,
      size: 999
    })
    // console.log(2222, rows)
    this.roleList = rows
  },
  methods: {
    //   获取当前员工所拥有的的角色id
    async getRoleIds(employeeId) {
      this.employeeId = employeeId
      const { roleIds } = await getUserDetailById(employeeId)
      //   console.log(3333, roleIds)
      //   回显所拥有的的角色id
      this.roleIds = roleIds
    },
    async btnOK() {
      await assignRole({
        id: this.employeeId,
        roleIds: this.roleIds
      })
      this.$message.success('角色更新成功')
      this.$emit('update:isShowDialog', false)
    },

    btnCancel() {
      this.roleIds = []
      this.$emit('update:isShowDialog', false)
      console.log(5555, this.isShowDialog)
    }
  }
}
</script>

<style>

</style>
